#!/usr/bin/env node

const http = require('http'),
        log = console.log;

http.createServer((req, res) => {
  log(`${req.method} ${req.url} HTTP/${req.httpVersion}`);
  log(req.headers);
  log();
  log(req.headers.host);
  log(req.headers['user-agent']);
  log(req.headers.authorization);
  log(req.headers['content-type']);

  //get username and password
  let auth = req.headers.authorization;
  auth = auth.split(' ')[1];
  auth = Buffer.from(auth,'base64');
  log(auth.toString('utf8'));
  auth = auth.toString('utf8').split(":");
  log("username:",auth[0]);
  log("password:",auth[1])
  res.end('ok') 
}).listen(8080);
